﻿Public Class ThanhToanTheForm
    Dim dt As DataTable
    Dim filter As String = ""
    Private Sub Button3_Click(sender As System.Object, e As System.EventArgs)
        Me.Dispose()
    End Sub
    Sub reload()
        dt = ChiTietSuDungTheDAO.GetAll(MainForm.current_user.MaUser)        
        dg.DataSource = dt
        dt.DefaultView.RowFilter = filter
    End Sub
    Private Sub NganHangForm_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load        
        reload()        
        dg.Columns("MaTheTinDung").HeaderText = "Mã Thẻ Tín Dụng"
        dg.Columns("No").HeaderText = "Số Tiền Đã Sử Dụng"
        dg.Columns("TongSoTienDaTra").HeaderText = "Số Tiền Đã Trả"
        dg.Columns("ConLai").HeaderText = "Còn Lại"
        dg.Columns("thangsudung").HeaderText = "Tháng"
        dg.Columns("namsudung").Visible = False
        Dim btn As New DataGridViewButtonColumn()
        btn.HeaderText = ""
        btn.Text = "Thanh Toán"
        btn.Name = "btn"
        btn.UseColumnTextForButtonValue = True
        dg.Columns.Add(btn)
    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Me.Dispose()
    End Sub

    Private Sub rbThangHienTai_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles rbThangHienTai.CheckedChanged
        filter = "thangsudung = " & Today.Month
        dt.DefaultView.RowFilter = filter
    End Sub

    Private Sub rbTatCa_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles rbTatCa.CheckedChanged
        filter = ""
        dt.DefaultView.RowFilter = filter
    End Sub

    Private Sub rbNamHienTai_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles rbNamHienTai.CheckedChanged
        filter = "namsudung = " & Today.Year
        dt.DefaultView.RowFilter = filter
    End Sub

    Private Sub dg_CellClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dg.CellClick
        If dg.CurrentCell.Value.ToString() = "Thanh Toán" Then
            Dim conlai As Double
            If dg.CurrentRow.Cells("ConLai").Value.ToString().Length = 0 Then
                conlai = 0
            Else
                conlai = dg.CurrentRow.Cells("ConLai").Value
            End If
            If conlai <= 0 Then
                MessageBox.Show("Giao dịch đã được thanh toán trước đó.")
                Return
            End If
            Dim mf As New SubThanhToanTheForm(conlai, dg.CurrentRow.Cells("MaTheTinDung").Value.ToString(), dg.CurrentRow.Cells("thangsudung").Value.ToString(), dg.CurrentRow.Cells("namsudung").Value.ToString())
            If mf.ShowDialog() = Windows.Forms.DialogResult.OK Then
                reload()
            End If
        End If

    End Sub

    Private Sub dg_CellFormatting(sender As System.Object, e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles dg.CellFormatting
        
    End Sub
End Class